class MyClass:
    __slots__ = ['name', 'age']


my_obj = MyClass()
my_obj.name = "Alice"
my_obj.age = 25
print(my_obj.name)  # 输出：Alice
print(my_obj.age)  # 输出：25

# 尝试添加其他属性
try:
    my_obj.gender = "Female"
except AttributeError as e:
    print(e)  # 输出：'MyClass' object has no attribute 'gender'
